import java.awt.event.KeyEvent;

import org.powerbot.core.script.job.Task;
import org.powerbot.core.script.job.state.Node;
import org.powerbot.game.api.methods.Widgets;
import org.powerbot.game.api.methods.input.Keyboard;
import org.powerbot.game.api.methods.input.Mouse;
import org.powerbot.game.api.methods.interactive.Players;
import org.powerbot.game.api.util.Random;
import org.powerbot.game.api.wrappers.interactive.Player;


public class EOCFixer extends Node{

	@Override
	public boolean activate() {
		// TODO Auto-generated method stub
		return !Widgets.get(640).getChild(1).visible() || 
				!Widgets.get(137).getChild(56).getText().equals("[Press Enter to Chat]");
	}

	@Override
	public void execute() {
		// TODO Auto-generated method stub
		Player p = Players.getLocal();
		if(!Widgets.get(640).getChild(1).visible())
		{
			Mouse.click(Random.nextInt(501, 512), Random.nextInt(380, 385), true);
			
			Task.sleep(300);
		}
		if( !Widgets.get(137).getChild(56).getText().equals("[Press Enter to Chat]") )
		{
			Keyboard.sendKey((char)KeyEvent.VK_ESCAPE);
			Keyboard.sendKey((char)KeyEvent.VK_ESCAPE);
			if(Random.nextInt(0, 100)>50)
			{
				Keyboard.sendKey((char)KeyEvent.VK_ESCAPE);
			}
		}
	}
}
